//
//  ViewController.m
//  23阿里星球作业
//
//  Created by dllo on 16/8/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "CustomCollectionViewCell.h"
#import "Custom1CollectionViewCell.h"
#import "Custom2CollectionViewCell.h"
#import "CustomCollectionReusableView.h"
#import "BaseModel.h"
#import "ESRootClass.h"
#import "ALData.h"
#import "ALAction.h"
#import "ALSData.h"
#import "ALSAction.h"
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
@class ALData,ALAction,ALSData,ALSAction;
@class ALData,ALAction,ALData,ALAction;
@class QData,Action,Data,Action;
@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (nonatomic,strong) ESRootClass *esRootClass;



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self handleData];
//    _flow = [[UICollectionViewFlowLayout alloc] init];
//    _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:_flow];
//    _flow.itemSize = CGSizeMake((WIDTH - 10) / 3, 120);
//    _flow.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
//    _flow.minimumInteritemSpacing = 5;
//    _flow.minimumLineSpacing = 5;
//    _flow.sectionHeadersPinToVisibleBounds = YES;
    
    [_collectionView registerNib:[UINib nibWithNibName:@"CustomCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"collectionCell"];
    [_collectionView registerNib:[UINib nibWithNibName:@"Custom1CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"collection1Cell"];
    [_collectionView registerNib:[UINib nibWithNibName:@"Custom2CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"collection2Cell"];
//    [_collectionView registerNib:[UINib nibWithNibName:@"UICollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionReuse"];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 5) {
        return CGSizeMake(WIDTH, 70);
    } else if (indexPath.section == 0) {
        return CGSizeMake((WIDTH - 15) / 2, 100);
    }
    return CGSizeMake((WIDTH - 20) / 3, 170);
    
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    CustomCollectionReusableView *reuse = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionReuse" forIndexPath:indexPath];
    reuse.backgroundColor = [UIColor blueColor];
//    reuse.headerTitleLabel.text = (NSString *)_esRootClass.data[indexPath.section];
    reuse.headerTitleLabel.text = @"标题";
    return reuse;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 8;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 1 || section == 4) {
        return 3;
    } else if (section == 2 || section == 3) {
        return 6;
    } else if (section == 0) {
    return 2;
    } else {
        return 6;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 5) {
        Custom1CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection1Cell" forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor orangeColor];
        
        return cell;
    } else if (indexPath.section == 0) {
        Custom2CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection2Cell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor greenColor];
        return cell;
    }
    else {
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    return cell;
    }
}


- (void)handleData
{
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
    [session GET:@"http://api.dongting.com/frontpage/frontpage?location=0&version=1470998222737&app=ttpod&v=v9.0.4.2016070616&user_id=0&mid=iPhone8%2C1&f=f320&s=s310&imsi=&hid=&splus=10.0&active=1&net=2&openudid=4bbd8925c4a3991ee51c9cd8b9a8dc5961820764&idfa=2BBAE4F7-2E3B-41AA-AE0C-F91FB2BDC279&utdid=V62kivWPJBYDABK%2FL8gCUnDI&alf=(null)&bundle_id=com.ttpod.music&latitude=(null)&longtitude=(null)&access_token=(null)&vc=9000400" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSData *data = responseObject;
        NSError *error = nil;
        id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
//        NSLog(@"%@",result);
        _esRootClass = [ESRootClass modelWithDic:result];

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

- (void)didReceiveMemoryWarning {

    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end

